package net.fdukedom.epicurus.pm.client;

import java.util.ResourceBundle;
import java.util.Map;
import javax.swing.JPanel;

import net.fdukedom.epicurus.client.plugin.ClientPluginInterface;
import net.fdukedom.epicurus.client.plugin.PageNotFoundException;
import net.fdukedom.epicurus.pm.client.panels.InboxPanel;
import net.fdukedom.epicurus.pm.client.panels.ViewMessagePanel;
import net.fdukedom.epicurus.resource.ResourceDispatcher;

public class PMClientPlugin implements ClientPluginInterface {
	/**
	 * Private messaging
	 */
	static final public String PLUGINNAME = "privateMessaging";

	/**
	 * View message
	 */
	static final public String VIEW_MESSAGE_PAGE = "../pm/viewMessage";

	/**
	 * View message
	 */
	static final public String INBOX_PAGE = ResourceDispatcher.getInstance()
			.getBundledValue("bundles.pm.Extensions", "pm.menu.actionLink");

	/**
	 * View message
	 */
	static final public String PARAMETER_MESSAGE_ID = "MessageID";

	public JPanel createPage(String pageLocation, Map<String, Object> parameter)
			throws PageNotFoundException {
		if (pageLocation.equals(INBOX_PAGE)) {
			return new InboxPanel();
		} else if (pageLocation.equals(VIEW_MESSAGE_PAGE)) {
			Integer msgID = (Integer) parameter.get(PARAMETER_MESSAGE_ID);
			if (msgID != null) {
				return new ViewMessagePanel(msgID.intValue());
			} else {
				throw new PageNotFoundException("Page unical name: " + pageLocation + " incorrect parameters.");
			}
		} else {
			throw new PageNotFoundException("Page unical name: " + pageLocation);
		}
	}
}
